﻿Imports System.Xml
Imports System.Collections.Specialized

Public Class frmTabDetailedDescription

    Public Shared selectedNode2Add As String = ""
    Public Shared selectedNode4Add As TreeNode = New TreeNode()
    Public Shared selectedNode As TreeNode
    Public Shared treeNodes As TreeNodeCollection
    Public Shared entityType As String = ""
    'edit
    'variables for Entity and Attribute Information
    Public Shared cEAentities As New Collection() 'the detail descriptions
    Public Shared cEAttribs As New Collection() 'the attributes descriptions
    Public Shared cEAdomains As New Collection() 'the domain values
    Public Shared cEAdomtypes As New Collection() 'the domain types
    Public Shared cEAttrOver As New Collection()   'the overview descriptions
    Public Shared sPdelim As String = "£"
    Dim editNode As EditXML = New EditXML()

#Region "Buttons"
    Private Sub button_new_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_new.Click
        Dim frmNewItem As New dialog_newEA()
        frmNewItem.ShowDialog()
        If frmNewItem.getSelection() = "entity" Then
            NewEntity()
        ElseIf frmNewItem.getSelection() = "attribute" Then
            NewAttribute()
        ElseIf frmNewItem.getSelection() = "domainvalue" Then
            NewDomainValue()
        End If
    End Sub

    Private Sub button_delete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_delete.Click
        If (CountCheckedNodes(treeview_elements.Nodes(0)) <> 0) Then
            Dim result As MsgBoxResult
            result = MsgBox("Would you like to delete ALL checked nodes?", MsgBoxStyle.YesNo, "Warning")
            If result = MsgBoxResult.Yes Then
                DeleteNode(treeview_elements.Nodes(0))
            End If
        Else
            MsgBox("Please select a node first.", MsgBoxStyle.OkOnly, "Error")
        End If
    End Sub

    Private Sub button_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_edit.Click
        Dim elementType As String = ""

        For Each entity As EAdetailClass In cEAentities
            If entity.EntityLabel = treeview_elements.SelectedNode.Text Then elementType = "Entity"
        Next
        For Each entity As Object In cEAdomains
            If TypeOf entity Is AttribDomain_Enum Then
                Dim temp As String = "Enumerated: " & entity.DomainValue
                If temp = treeview_elements.SelectedNode.Text Then elementType = "DomainValue_Enum"
            ElseIf TypeOf entity Is AttribDomain_Range Then
                Dim temp As String = "Range: min = " & entity.DomMinimum & "  max = " & entity.DomMaximum
                If temp = treeview_elements.SelectedNode.Text Then elementType = "DomainValue_Range"
            ElseIf TypeOf entity Is String Then
                Dim temp As String = entity
                Dim temp2() As String = Split(temp, sPdelim)
                temp = "Codeset: " & temp2(0)
                If temp = treeview_elements.SelectedNode.Text Then elementType = "DomainValue_Codeset"
                Dim temp3 As String = entity
                temp3 = "Unrepresentable: " & temp3
                If temp3 = treeview_elements.SelectedNode.Text Then elementType = "DomainValue_Unrep"
            End If
        Next
        For Each entity As AttribClass In cEAttribs
            If entity.Label = treeview_elements.SelectedNode.Text Then elementType = "Attribute"
        Next

        Select Case elementType
            Case "Entity"
                EditEntity()
            Case "DomainValue_Enum"
                EditDomainValue("enum")
            Case "DomainValue_Range"
                EditDomainValue("range")
            Case "DomainValue_Codeset"
                EditDomainValue("codeset")
            Case "DomainValue_Unrep"
                EditDomainValue("unrep")
            Case "Attribute"
                EditAttribute()
            Case Else
                MsgBox("Error")
        End Select
    End Sub

    Private Sub button_example_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_example.Click
        Dim helpForm As dialog_help = New dialog_help("DetailedDescription")
        helpForm.ShowDialog()
    End Sub
#End Region

#Region "Righ Click Menu Items"
    Private Sub EDITToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EDITToolStripMenuItem.Click
        If button_edit.Enabled = True Then button_edit_Click(sender, e)
    End Sub

    Private Sub DELETEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DELETEToolStripMenuItem.Click
        If button_delete.Enabled = True Then button_delete_Click(sender, e)
    End Sub

    Private Sub CollaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CollapseToolStripMenuItem.Click
        treeview_elements.Nodes(0).Collapse(False)
    End Sub

    Private Sub ExpandAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExpandAllToolStripMenuItem.Click
        treeview_elements.Nodes(0).ExpandAll()
    End Sub

    Private Sub frmTabDetailedDescription_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        treeview_elements.Nodes(0).ExpandAll()
    End Sub

    Private Sub NewEntityToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewEntityToolStripMenuItem.Click
        NewEntity()
    End Sub

    Private Sub NewAttributeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewAttributeToolStripMenuItem.Click
        NewAttribute()
    End Sub

    Private Sub NewDomainValueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewDomainValueToolStripMenuItem.Click
        NewDomainValue()
    End Sub

    Dim clipBoardNode As TreeNode = New TreeNode()
    Dim clipBoardNodePath As String = ""
    Dim coppied As Boolean = False
    Dim cutted As Boolean = False
    Private Sub COPYToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COPYToolStripMenuItem.Click
        clipBoardNode = treeview_elements.SelectedNode.Clone()
        clipBoardNodePath = treeview_elements.SelectedNode.FullPath
        coppied = True
        PASTEToolStripMenuItem.Enabled = True
    End Sub

    Private Sub CUTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CUTToolStripMenuItem.Click
        clipBoardNode = treeview_elements.SelectedNode.Clone()
        clipBoardNodePath = treeview_elements.SelectedNode.FullPath
        cutted = True
        PASTEToolStripMenuItem.Enabled = True
    End Sub

    Private Sub PASTEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PASTEToolStripMenuItem.Click
        If pasteOperationControl() Then
            If cutted Then
                treeview_elements.SelectedNode.Nodes.Add(clipBoardNode)
                CreateCopyofElement(clipBoardNodePath, treeview_elements.SelectedNode.FullPath, False)
                findNode(treeview_elements.Nodes, clipBoardNodePath, "", 0, 0).Remove()
            ElseIf coppied Then
                treeview_elements.SelectedNode.Nodes.Add(clipBoardNode)
                CreateCopyofElement(clipBoardNodePath, treeview_elements.SelectedNode.FullPath, True)
            End If
            treeview_elements.SelectedNode.ExpandAll()
            coppied = False
            cutted = False
            PASTEToolStripMenuItem.Enabled = False
        End If
    End Sub
    Private Function pasteOperationControl() As Boolean
        Dim copiedElement As String = getElementType(clipBoardNodePath)
        Dim toPasteElement As String = getElementType(treeview_elements.SelectedNode.FullPath)
        If copiedElement = "Entity" Then
            If toPasteElement = "ROOT" Then
                Return True
            Else
                MsgBox("You can paste Entity only into Root", MsgBoxStyle.Exclamation, "Paste Error")
                Return False
            End If
        ElseIf copiedElement = "Attribute" Then
            If toPasteElement = "Entity" Or toPasteElement = "enum" Or toPasteElement = "range" Then
                Return True
            Else
                MsgBox("You can paste Attribute only into an Entity or Enumerated Domain Value or Range Domain Value", MsgBoxStyle.Exclamation, "Paste Error")
                Return False
            End If
        Else
            If toPasteElement = "Attribute" Then
                Return True
            Else
                MsgBox("You can paste a Domain Value only into an Attribute", MsgBoxStyle.Exclamation, "Paste Error")
                Return False
            End If
        End If
        Return False
    End Function
    Public Function getElementType(ByVal path As String) As String
        Dim elementType As String = ""
        If path = "ROOT" Then Return "ROOT"
        Try
            Dim dummy As EAdetailClass = cEAentities(path)
            elementType = "Entity"
        Catch ex As Exception
        End Try
        Try
            Dim dummy As AttribClass = cEAttribs(path)
            elementType = "Attribute"
        Catch ex As Exception
        End Try
        Try
            Dim dummy As String = cEAdomtypes(path)
            elementType = dummy
        Catch ex As Exception
        End Try
        Return elementType
    End Function
    Private Sub CreateCopyofElement(ByVal clipBoardTreeNodePath As String, ByVal pasteTreeNodePath As String, ByVal firstNode As Boolean)
        Try
            Dim entity As EAdetailClass = cEAentities(clipBoardTreeNodePath)
            Dim newEntity As EAdetailClass = entity.Duplicate()
            If firstNode Then newEntity.EntityLabel = "Copy of " & newEntity.EntityLabel
            pasteTreeNodePath = pasteTreeNodePath & "\" & newEntity.EntityLabel
            cEAentities.Add(newEntity, pasteTreeNodePath)
        Catch ex As Exception
        End Try
        Try
            Dim attrib As AttribClass = cEAttribs(clipBoardTreeNodePath)
            Dim newAttrib As AttribClass = attrib.Duplicate()
            If firstNode Then newAttrib.Label = "Copy of " & newAttrib.Label
            pasteTreeNodePath = pasteTreeNodePath & "\" & newAttrib.Label
            cEAttribs.Add(newAttrib, pasteTreeNodePath)
        Catch ex As Exception
        End Try

        Dim domain_enum As AttribDomain_Enum = New AttribDomain_Enum()
        Dim domain_range As AttribDomain_Range = New AttribDomain_Range()
        Dim domain_string As String = ""
        Dim newdomain_enum As AttribDomain_Enum = New AttribDomain_Enum()
        Dim newdomain_range As AttribDomain_Range = New AttribDomain_Range()
        Dim newdomain_string As String = ""
        Try
            Dim domainType As String = cEAdomtypes(clipBoardTreeNodePath)
            If domainType = "enum" Then
                domain_enum = cEAdomains(clipBoardTreeNodePath)
                newdomain_enum = domain_enum.Duplicate()
                If firstNode Then newdomain_enum.DomainValue = "Copy of " & newdomain_enum.DomainValue
                Dim s1 As String = "Enumerated: " & newdomain_enum.DomainValue
                pasteTreeNodePath = pasteTreeNodePath & "\" & s1
                cEAdomains.Add(newdomain_enum, pasteTreeNodePath)
                cEAdomtypes.Add("enum", pasteTreeNodePath)
            ElseIf domainType = "range" Then
                domain_range = cEAdomains(clipBoardTreeNodePath)
                newdomain_range = domain_range.Duplicate()
                'If firstNode Then newdomain_range.DomMaximum = "Copy of " & newdomain_range.DomMaximum
                Dim s1 As String = "Range: min = " & newdomain_range.DomMinimum & "  max = " & newdomain_range.DomMaximum
                pasteTreeNodePath = pasteTreeNodePath & "\" & s1
                cEAdomains.Add(newdomain_range, pasteTreeNodePath)
                cEAdomtypes.Add("range", pasteTreeNodePath)
            ElseIf domainType = "codeset" Then
                domain_string = cEAdomains(clipBoardTreeNodePath)
                newdomain_string = domain_string
                If firstNode Then newdomain_string = "Copy of " & newdomain_string
                Dim sGenArray() As String = Split(newdomain_string, sPdelim)
                Dim s1 As String = "Codeset: " & sGenArray(0)
                pasteTreeNodePath = pasteTreeNodePath & "\" & s1
                cEAdomains.Add(newdomain_string, pasteTreeNodePath)
                cEAdomtypes.Add("codeset", pasteTreeNodePath)
            Else
                domain_string = cEAdomains(clipBoardTreeNodePath)
                newdomain_string = domain_string
                If firstNode Then newdomain_string = "Copy of " & newdomain_string
                Dim s1 As String = "Unrepresentable: " & newdomain_string
                pasteTreeNodePath = pasteTreeNodePath & "\" & s1
                cEAdomains.Add(newdomain_string, pasteTreeNodePath)
                cEAdomtypes.Add("unrep", pasteTreeNodePath)
            End If
        Catch ex As Exception
        End Try
        Dim myNode As TreeNode = findNode(treeview_elements.Nodes, clipBoardTreeNodePath, "", 0, 0)
        For Each subnode As TreeNode In myNode.Nodes
            CreateCopyofElement(subnode.FullPath, pasteTreeNodePath, False)
        Next
        If firstNode Then
            If clipBoardNode.Name.StartsWith("Codeset:") Then
                clipBoardNode.Name = "Codeset: " & newdomain_string.Split(sPdelim)(0)
                clipBoardNode.Text = clipBoardNode.Name
            ElseIf clipBoardNode.Name.StartsWith("Unrepresentable:") Then
                clipBoardNode.Name = "Unrepresentable: " & newdomain_string
                clipBoardNode.Text = clipBoardNode.Name
            ElseIf clipBoardNode.Name.StartsWith("Range:") Then
            ElseIf clipBoardNode.Name.StartsWith("Enumerated:") Then
                clipBoardNode.Name = "Enumerated: " & newdomain_enum.DomainValue
                clipBoardNode.Text = clipBoardNode.Name
            Else
                clipBoardNode.Name = "Copy of " & clipBoardNode.Name
                clipBoardNode.Text = "Copy of " & clipBoardNode.Text
            End If
        End If
    End Sub
    Private Function findNode(ByVal treenodes As TreeNodeCollection, ByVal fullPathName As String, ByVal nodeName As String, ByVal startIndex As Integer, ByVal depth As Integer) As TreeNode
        Dim paths() As String = fullPathName.Split("\")
        If depth = 0 Then depth = paths.GetLength(0)
        If nodeName = "" Then nodeName = paths(startIndex)
        For Each item As TreeNode In treenodes
            If item.Name = nodeName Then
                If startIndex + 1 < depth Then
                    Return findNode(item.Nodes, fullPathName, paths(startIndex + 1), startIndex + 1, depth)
                Else
                    Return item
                End If
            End If
        Next
        Return Nothing
    End Function
#End Region

#Region "Delete Elements"
    Private Sub DeleteNode(ByVal node As TreeNode)
        For Each subnode As TreeNode In node.Nodes
            DeleteNode(subnode)
        Next
        If node.Checked = True And node.FullPath <> "ROOT" Then
            DeleteEntity(node)
            editXMLFile()
            node.Remove()
        End If
    End Sub
    Private Sub DeleteEntity(ByVal entityNode As TreeNode)
        For Each entity As EAdetailClass In cEAentities
            Try
                cEAentities.Remove(entityNode.FullPath)
            Catch ex As Exception

            End Try
        Next
        For Each entity As Object In cEAdomains
            Try
                cEAdomains.Remove(entityNode.FullPath)
                cEAdomtypes.Remove(entityNode.FullPath)
            Catch ex As Exception
            End Try
        Next
        For Each entity As AttribClass In cEAttribs
            Try
                cEAttribs.Remove(entityNode.FullPath)
            Catch ex As Exception
            End Try
        Next

    End Sub
#End Region

#Region "Edit Elements"
    Private Sub EditEntity()
        getSelectedNodeParent()
        entityType = "Entity"
        Dim node2update As TreeNode = treeview_elements.SelectedNode
        Dim node2change As String = node2update.FullPath
        Dim oToEdit As EAdetailClass = cEAentities(node2change)
        Dim node2updateText As String = node2update.Text
        Dim node2updateParent As String = node2update.Parent.Text
        Dim s1 As String = ""

        Dim frmEditDetails As New frmEAdetail(oToEdit)
        frmEditDetails.ShowDialog()
        Dim node2add As String = selectedNode2Add
        If frmEditDetails.getUpdated() Then
            s1 = frmEditDetails.getEntity().EntityLabel
            node2update.Text = s1
            node2update.Name = s1
            If (node2add <> node2updateParent) Then
                Dim node As TreeNode = New TreeNode()
                node = selectedNode4Add
                treeview_elements.Nodes.Remove(node2update)
                node.Nodes.Add(node2update)
                node.Expand()
            End If
            cEAentities.Remove(node2change)
            cEAentities.Add(frmEditDetails.getEntity(), node2update.FullPath)
            treeview_elements.Update()
        End If
        node2update.Expand()
        editXMLFile()
    End Sub
    Private Sub EditDomainValue(ByVal type As String)
        getSelectedNodeParent()
        entityType = "DomainValue"
        Dim s1 As String = ""

        If type = "enum" Then
            Dim oToEdit As AttribDomain_Enum = cEAdomains(treeview_elements.SelectedNode.FullPath)
            Dim frmEditValue As New frmAttribDomain(oToEdit)
            frmEditValue.ShowDialog()
            EditDomainValues(frmEditValue, type)
        ElseIf type = "range" Then
            Dim oToEdit As AttribDomain_Range = cEAdomains(treeview_elements.SelectedNode.FullPath)
            Dim frmEditValue As New frmAttribDomain(oToEdit)
            frmEditValue.ShowDialog()
            EditDomainValues(frmEditValue, type)
        ElseIf type = "codeset" Then
            Dim oToEdit As String = cEAdomains(treeview_elements.SelectedNode.FullPath)
            Dim frmEditValue As New frmAttribDomain(type, oToEdit)
            frmEditValue.ShowDialog()
            EditDomainValues(frmEditValue, type)
        ElseIf type = "unrep" Then
            Dim oToEdit As String = cEAdomains(treeview_elements.SelectedNode.FullPath)
            Dim frmEditValue As New frmAttribDomain(type, oToEdit)
            frmEditValue.ShowDialog()
            EditDomainValues(frmEditValue, type)
        End If
        editXMLFile()
    End Sub
    Private Sub EditDomainValues(ByVal frmEditValue As frmAttribDomain, ByVal type As String)
        Dim node2update As TreeNode = treeview_elements.SelectedNode
        Dim node2change As String = node2update.FullPath
        Dim node2updateText As String = node2update.Text
        Dim node2updateParent As String = node2update.Parent.Text

        Dim node2add As String = selectedNode2Add

        If frmEditValue.getUpdated() Then
            cEAdomains.Remove(node2change)
            Dim s1 As String
            If (type = "enum") Then
                s1 = "Enumerated: " & frmEditValue.getDomainED().DomainValue
            ElseIf (type = "range") Then
                s1 = "Range: min = " & frmEditValue.getDomainRD().DomMinimum & "  max = " & frmEditValue.getDomainRD().DomMaximum
            ElseIf (type = "codeset") Then
                Dim sGenArray() As String = Split(frmEditValue.getCodeSet(), sPdelim)
                s1 = "Codeset: " & sGenArray(0)
            Else
                s1 = "Unrepresentable: " & frmEditValue.getUnrepped()
            End If

            node2update.Text = s1
            node2update.Name = s1

            If (node2add <> node2updateParent) Then
                Dim node As TreeNode = New TreeNode()
                node = selectedNode4Add
                treeview_elements.Nodes.Remove(node2update)
                node.Nodes.Add(node2update)
                node.Expand()
            End If

            If (type = "enum") Then
                cEAdomains.Add(frmEditValue.getDomainED(), node2update.FullPath)
            ElseIf (type = "range") Then
                cEAdomains.Add(frmEditValue.getDomainRD(), node2update.FullPath)
            ElseIf (type = "codeset") Then
                cEAdomains.Add(frmEditValue.getCodeSet(), node2update.FullPath)
            Else
                cEAdomains.Add(frmEditValue.getUnrepped(), node2update.FullPath)
            End If

            treeview_elements.Update()
        End If
        node2update.Expand()
    End Sub
    Private Sub EditAttribute()
        getSelectedNodeParent()
        entityType = "Attribute"

        Dim node2update As TreeNode = treeview_elements.SelectedNode
        Dim node2change As String = node2update.FullPath
        Dim oToEdit As AttribClass = cEAttribs(node2change)
        Dim node2updateText As String = node2update.Text
        Dim node2updateParent As String = node2update.Parent.Text
        Dim frmEditAttrib As New frmAttributes(oToEdit)
        frmEditAttrib.ShowDialog()
        Dim node2add As String = selectedNode2Add
        Dim s1 As String = ""

        If (frmEditAttrib.getUpdated() = True) Then
            s1 = frmEditAttrib.getAttrib().Label
            node2update.Text = s1
            node2update.Name = s1
            If (node2add <> node2updateParent) Then
                Dim node As TreeNode = New TreeNode()
                node = selectedNode4Add
                treeview_elements.Nodes.Remove(node2update)
                node.Nodes.Add(node2update)
                node.Expand()
            End If
            cEAttribs.Remove(node2change)
            cEAttribs.Add(frmEditAttrib.getAttrib(), node2update.FullPath)
            treeview_elements.Update()
        End If
        node2update.Expand()
        editXMLFile()
    End Sub
#End Region

#Region "New Elements"
    Private Sub NewEntity()
        getSelectedNode()
        entityType = "Entity"
        Dim s1 As String = ""
        Dim frmNewDetails As New frmEAdetail()
        frmNewDetails.ShowDialog()
        If (frmNewDetails.getUpdated() = True) Then
            s1 = frmNewDetails.getEntity().EntityLabel

            Dim node2add As String = selectedNode2Add
            Dim node As TreeNode = New TreeNode()
            node = selectedNode4Add
            Dim newNode As TreeNode = New TreeNode()
            newNode.Text = s1
            newNode.Name = s1
            node.Nodes.Add(newNode)
            cEAentities.Add(frmNewDetails.getEntity(), newNode.FullPath()) 'add new detailed description to collection with key
            node.Expand()
            editXMLFile()
        End If
    End Sub
    '    Private Function recursiveTreeView(ByVal n As TreeNode, ByVal s As String) As TreeNode
    '        If n.Text = s Then Return n
    '    Dim returnNode As TreeNode = New TreeNode()
    '        For Each aNode As TreeNode In n.Nodes
    '            returnNode = recursiveTreeView(aNode, s)
    '            If (returnNode.Text <> "") Then Return returnNode
    '        Next
    '        Return returnNode
    '    End Function
    Private Sub NewAttribute()
        getSelectedNode()
        entityType = "Attribute"

        Dim frmNewAttrib As New frmAttributes
        Dim s1 As String = ""
        frmNewAttrib.ShowDialog()
        If (frmNewAttrib.getUpdated() = True) Then
            s1 = frmNewAttrib.getAttrib().Label
            Dim node2add As String = selectedNode2Add
            Dim node As TreeNode = New TreeNode()
            node = selectedNode4Add
            Dim newNode As TreeNode = New TreeNode()
            newNode.Text = s1
            newNode.Name = s1
            node.Nodes.Add(newNode)
            cEAttribs.Add(frmNewAttrib.getAttrib(), newNode.FullPath()) 'add the new attribute to collection
            node.Expand()
            editXMLFile()
        End If
    End Sub
    Private Sub NewDomainValue()
        getSelectedNode()
        entityType = "DomainValue"

        Dim sCurDomType As String = ""
        Dim sGenArray() As String
        Dim s1 As String = ""
        Dim frmNewValue As New frmAttribDomain

        frmNewValue.ShowDialog()
        If (frmNewValue.getUpdated() = True) Then
            sCurDomType = frmNewValue.getDomType()
            If (sCurDomType = "enum") Then
                s1 = "Enumerated: " & frmNewValue.getDomainED().DomainValue
            ElseIf (sCurDomType = "range") Then
                s1 = "Range: min = " & frmNewValue.getDomainRD().DomMinimum & "  max = " & frmNewValue.getDomainRD().DomMaximum
            ElseIf (sCurDomType = "codeset") Then
                sGenArray = Split(frmNewValue.getCodeSet(), sPdelim)
                s1 = "Codeset: " & sGenArray(0)
            Else
                s1 = "Unrepresentable: " & frmNewValue.getUnrepped()
            End If
            Dim node2add As String = selectedNode2Add
            Dim node As TreeNode = New TreeNode()
            node = selectedNode4Add
            Dim newNode As TreeNode = New TreeNode()
            newNode.Text = s1
            newNode.Name = s1
            node.Nodes.Add(newNode)
            node.Expand()
            If (sCurDomType = "enum") Then
                cEAdomains.Add(frmNewValue.getDomainED(), newNode.FullPath()) 'add domain value to collection
            ElseIf (sCurDomType = "range") Then
                cEAdomains.Add(frmNewValue.getDomainRD(), newNode.FullPath())
            ElseIf (sCurDomType = "codeset") Then
                cEAdomains.Add(frmNewValue.getCodeSet(), newNode.FullPath())
            Else
                cEAdomains.Add(frmNewValue.getUnrepped(), newNode.FullPath())
            End If
            cEAdomtypes.Add(sCurDomType, newNode.FullPath())
            editXMLFile()
        End If
    End Sub
#End Region

#Region "Treeview Events"
    Private Function CountCheckedNodes(ByVal rootNode As TreeNode) As Integer
        Dim count As Integer = 0
        If rootNode.Checked Then count = 1
        For Each tvn As TreeNode In rootNode.Nodes
            count += CountCheckedNodes(tvn)
        Next
        Return count
    End Function
    Private Sub SelectChildNodes(ByVal parentNode As TreeNode)
        parentNode.Checked = True
        For Each child As TreeNode In parentNode.Nodes
            SelectChildNodes(child)
        Next
    End Sub
    Private Sub UnSelectChildNodes(ByVal parentNode As TreeNode)
        parentNode.Checked = False
        For Each child As TreeNode In parentNode.Nodes
            UnSelectChildNodes(child)
        Next
    End Sub
    Dim done As Boolean = False
    Private Sub treeview_elements_AfterCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeview_elements.AfterCheck
        If (done = False) Then
            If (e.Node.Checked) Then done = True : UnSelectChildNodes(e.Node) Else done = True : SelectChildNodes(e.Node)
            If (CountCheckedNodes(treeview_elements.Nodes(0)) = 0) Then button_delete.Enabled = False Else button_delete.Enabled = True
            If button_delete.Enabled = True Then
                DELETEToolStripMenuItem.Enabled = True
                button_export.Enabled = True
                SelectedItemsToolStripMenuItem.Enabled = True
            Else
                DELETEToolStripMenuItem.Enabled = False
                button_export.Enabled = False
                SelectedItemsToolStripMenuItem.Enabled = False
            End If

        End If
    End Sub
    Private Sub treeview_elements_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeview_elements.MouseClick
        done = False
    End Sub
    Private Sub treeview_elements_NodeMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles treeview_elements.NodeMouseClick
        If e.Button = Windows.Forms.MouseButtons.Right Then treeview_elements.SelectedNode = e.Node
        If (e.Node.Checked) Then done = True : UnSelectChildNodes(e.Node) Else done = True : SelectChildNodes(e.Node)
        If (CountCheckedNodes(treeview_elements.Nodes(0)) = 0) Then button_delete.Enabled = False Else button_delete.Enabled = True
        If button_delete.Enabled = True Then
            DELETEToolStripMenuItem.Enabled = True
            button_export.Enabled = True
            SelectedItemsToolStripMenuItem.Enabled = True
        Else
            DELETEToolStripMenuItem.Enabled = False
            button_export.Enabled = False
            SelectedItemsToolStripMenuItem.Enabled = False
        End If
    End Sub
    Private Sub treeview_elements_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles treeview_elements.AfterSelect
        If (e.Node.Text = "ROOT") Then button_edit.Enabled = False Else button_edit.Enabled = True
        If button_edit.Enabled = True Then
            EDITToolStripMenuItem.Enabled = True
            COPYToolStripMenuItem.Enabled = True
            CUTToolStripMenuItem.Enabled = True
        Else
            EDITToolStripMenuItem.Enabled = False
            COPYToolStripMenuItem.Enabled = False
            CUTToolStripMenuItem.Enabled = False
        End If
    End Sub
    Private Sub getSelectedNode()
        selectedNode = treeview_elements.SelectedNode
        treeNodes = treeview_elements.Nodes
    End Sub
    Private Sub getSelectedNodeParent()
        selectedNode = treeview_elements.SelectedNode.Parent
        treeNodes = treeview_elements.Nodes
    End Sub
#End Region

#Region "Keyboard Events"
    Private Sub treeview_elements_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles treeview_elements.KeyDown
        Select Case e.KeyCode
            Case Keys.Delete
                If e.Shift Then
                    If CUTToolStripMenuItem.Enabled = True Then CUTToolStripMenuItem_Click(sender, e)
                Else
                    If button_delete.Enabled = True Then button_delete_Click(sender, e)
                End If
            Case Keys.Insert
                If e.Control Then
                    If COPYToolStripMenuItem.Enabled = True Then COPYToolStripMenuItem_Click(sender, e)
                ElseIf e.Shift Then
                    If PASTEToolStripMenuItem.Enabled = True Then PASTEToolStripMenuItem_Click(sender, e)
                Else
                    button_new_Click(sender, e)
                End If
            Case Keys.Enter
                If button_edit.Enabled = True Then button_edit_Click(sender, e)
            Case Keys.F2
                If button_edit.Enabled = True Then button_edit_Click(sender, e)
            Case Keys.C
                If e.Control And COPYToolStripMenuItem.Enabled = True Then COPYToolStripMenuItem_Click(sender, e)
            Case Keys.X
                If e.Control And CUTToolStripMenuItem.Enabled = True Then CUTToolStripMenuItem_Click(sender, e)
            Case Keys.V
                If e.Control And PASTEToolStripMenuItem.Enabled = True Then PASTEToolStripMenuItem_Click(sender, e)
        End Select
    End Sub
    Private Sub treeview_elements_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles treeview_elements.MouseDoubleClick
        If button_edit.Enabled = True Then button_edit_Click(sender, e)
    End Sub
#End Region

#Region "XML Operations"
    Public Sub editXMLFile()
        editNode.Remove("/metadata/eainfo", "detailed")
        Dim newNode As String = ""
        For Each item As TreeNode In treeview_elements.Nodes(0).Nodes
            Try
                Dim value As EAdetailClass = cEAentities(item.FullPath)
                newNode = newNode & "<enttyp>"
                newNode = newNode & "<enttypl>" & value.EntityLabel & "</enttypl>"
                newNode = newNode & "<enttypd>" & value.EntityDef & "</enttypd>"
                newNode = newNode & "<enttypds>" & value.DefSource & "</enttypds>"
                newNode = newNode & "</enttyp>"
                For Each item2 As TreeNode In item.Nodes
                    newNode = newNode & createAttribute(item2)
                Next

            Catch ex As Exception
            End Try
        Next
        If newNode <> "" Then editNode.Add("/metadata/eainfo", "detailed", "detailed", newNode)
    End Sub
    Private Function createAttribute(ByVal item2 As TreeNode) As String
        Dim newNode As String = ""
        Try
            Dim value2 As AttribClass = cEAttribs(item2.FullPath)
            newNode = newNode & "<attr>"
            newNode = newNode & "<attrlabl>" & value2.Label & "</attrlabl>"
            newNode = newNode & "<attrdef>" & value2.Definition & "</attrdef>"
            newNode = newNode & "<attrdefs>" & value2.DefSource & "</attrdefs>"
            For i As Integer = 0 To value2.ValueDates.Count - 1
                Dim dates() As String = value2.ValueDates(i).Split(sPdelim)
                newNode = newNode & "<begdatea>" & dates(0) & "</begdatea>"
                If dates.GetUpperBound(0) = 1 Then newNode = newNode & "<enddatea>" & dates(1) & "</enddatea>"
            Next
            newNode = newNode & "<attrvai><attrva>" & value2.Accuracy & "</attrva><attrvae>" & value2.AccExplain & "</attrvae></attrvai>"
            newNode = newNode & "<attrmfrq>" & value2.MeasureFreq & "</attrmfrq>"
            For Each item3 As TreeNode In item2.Nodes
                Try
                    Dim type As String = cEAdomtypes(item3.FullPath)
                    newNode = newNode & "<attrdomv>"
                    If type = "enum" Then
                        Dim value3 As AttribDomain_Enum = cEAdomains(item3.FullPath)
                        newNode = newNode & "<edom>"
                        newNode = newNode & "<edomv>" & value3.DomainValue & "</edomv>"
                        newNode = newNode & "<edomvd>" & value3.ValueDef & "</edomvd>"
                        newNode = newNode & "<edomvds>" & value3.DefSource & "</edomvds>"
                        For Each item4 As TreeNode In item3.Nodes
                            newNode = newNode & createAttribute(item4)
                        Next
                        newNode = newNode & "</edom>"
                    ElseIf type = "range" Then
                        Dim value3 As AttribDomain_Range = cEAdomains(item3.FullPath)
                        newNode = newNode & "<rdom>"
                        newNode = newNode & "<rdommin>" & value3.DomMinimum & "</rdommin><rdommax>" & value3.DomMaximum & "</rdommax>"
                        newNode = newNode & "<attrunit>" & value3.MeasureUnits & "</attrunit>"
                        newNode = newNode & "<attrmres>" & value3.Resolution & "</attrmres>"
                        For Each item4 As TreeNode In item3.Nodes
                            newNode = newNode & createAttribute(item4)
                        Next
                        newNode = newNode & "</rdom>"
                    ElseIf type = "codeset" Then
                        Dim value3() As String = cEAdomains(item3.FullPath).split(sPdelim)
                        newNode = newNode & "<codesetd><codesetn>" & value3(0) & "</codesetn>"
                        newNode = newNode & "<codesets>" & value3(1) & "</codesets></codesetd>"
                    Else
                        Dim value3 As String = cEAdomains(item3.FullPath)
                        newNode = newNode & "<udom>" & value3 & "</udom>"
                    End If
                    newNode = newNode & "</attrdomv>"
                Catch ex As Exception
                End Try
            Next
            newNode = newNode & "</attr>"
        Catch ex As Exception
        End Try
        Return newNode
    End Function
    Private Sub frmTabDetailedDescription_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
        editXMLFile()
    End Sub
#End Region

#Region "Public get and Set functions"
    Public Function getEntityType() As String
        Return entityType
    End Function
    Public Function getTheSelectedNode() As TreeNode
        Return selectedNode
    End Function
    Public Sub setSelectedNode2Add(ByVal value As String)
        selectedNode2Add = value
        'selectedNode4Add = nodeValue
    End Sub
    Public Sub setSelectedNode2Add(ByVal value As String, ByVal nodeValue As TreeNode)
        selectedNode2Add = value
        selectedNode4Add = nodeValue
    End Sub
#End Region

#Region "Export/Import"
    Private Sub button_export_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_export.Click
        editXMLFile()
        Dim sTemp As String = ""
        If (treeview_elements.Nodes(0).Checked) Then 'export complete tree
            exportAllEntities()
        Else
            exportSelectedEntities()
        End If
    End Sub
    Private Function controlEntities() As Boolean
        Dim sTemp As String = ""
        If (treeview_elements.Nodes(0).Nodes.Count = 0) Then 'no nodes defined yet
            sTemp = "No nodes are currently defined." & vbCrLf & "Export to file not available."
            MessageBox.Show(sTemp, "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        ElseIf (CountCheckedNodes(treeview_elements.Nodes(0)) = 0) Then 'nodes exist but none are selected
            MessageBox.Show("No nodes are selected for export.", "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        End If
        Return True
    End Function
    Private Sub exportAllEntities()
        If treeview_elements.Nodes(0).Checked = False Then treeview_elements.Nodes(0).Checked = True
        If controlEntities() Then
            Dim sTemp As String = ""
            Dim sOutputXML As String = ""
            Dim xmlExportDoc As XmlDocument = New XmlDocument()

            SaveExportXML.ShowDialog()
            sOutputXML = SaveExportXML.FileName
            If (sOutputXML <> "") Then
                Dim newNode As String = "<detailed>"
                For Each item As TreeNode In treeview_elements.Nodes(0).Nodes
                    Try
                        Dim value As EAdetailClass = cEAentities(item.FullPath)
                        newNode = newNode & "<enttyp>"
                        newNode = newNode & "<enttypl>" & value.EntityLabel & "</enttypl>"
                        newNode = newNode & "<enttypd>" & value.EntityDef & "</enttypd>"
                        newNode = newNode & "<enttypds>" & value.DefSource & "</enttypds>"
                        newNode = newNode & "</enttyp>"
                        For Each item2 As TreeNode In item.Nodes
                            newNode = newNode & createAttribute(item2)
                        Next

                    Catch ex As Exception
                    End Try
                Next
                newNode = newNode & "</detailed>"
                xmlExportDoc.LoadXml(newNode)
                xmlExportDoc.Save(sOutputXML) 'write the XML node to the specified file
            Else
                sTemp = "No file name given. Save terminated!"
                MessageBox.Show(sTemp, "File save error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If
    End Sub
    Private Sub exportSelectedEntities()
        If controlEntities() Then
            Dim sTemp As String = ""
            Dim sOutputXML As String = ""
            Dim xmlExportDoc As XmlDocument = New XmlDocument()

            SaveExportXML.ShowDialog()
            sOutputXML = SaveExportXML.FileName
            If (sOutputXML <> "") Then
                Dim newNode As String = "<detailed>"
                For Each item As TreeNode In treeview_elements.Nodes(0).Nodes
                    Try
                        If item.Checked Then
                            Dim value As EAdetailClass = cEAentities(item.FullPath)
                            newNode = newNode & "<enttyp>"
                            newNode = newNode & "<enttypl>" & value.EntityLabel & "</enttypl>"
                            newNode = newNode & "<enttypd>" & value.EntityDef & "</enttypd>"
                            newNode = newNode & "<enttypds>" & value.DefSource & "</enttypds>"
                            newNode = newNode & "</enttyp>"
                            For Each item2 As TreeNode In item.Nodes
                                newNode = newNode & createAttribute(item2)
                            Next
                        End If
                    Catch ex As Exception
                    End Try
                Next
                newNode = newNode & "</detailed>"
                xmlExportDoc.LoadXml(newNode)
                xmlExportDoc.Save(sOutputXML) 'write the XML node to the specified file
            Else
                sTemp = "No file name given. Save terminated!"
                MessageBox.Show(sTemp, "File save error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If
    End Sub
    Private Sub button_import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button_import.Click
        editXMLFile()
        Dim xmlImportDoc As XmlDocument = New XmlDocument()
        Dim sError As String = ""
        If OpenImportXML.ShowDialog() = DialogResult.OK Then
            Try
                'load XML into Document Object Model (DOM)
                xmlImportDoc.Load(OpenImportXML.FileName)
            Catch ex As Exception
                sError = "Error loading taxonomic classification XML from specified file"
                MessageBox.Show(ex.Message, sError, MessageBoxButtons.OK, MessageBoxIcon.Error)
                OpenImportXML.Dispose()
                Return
            End Try
            OpenImportXML.Dispose()
        Else
            Return
        End If

        'check file matches entity structure
        If (xmlImportDoc.GetElementsByTagName("enttyp").Count() = 0) Then
            sError = "XML structure is not consistent with entity classification"
            MessageBox.Show(sError, "Import error", MessageBoxButtons.OK)
            Return
        End If

        Dim importXML As String = xmlImportDoc.SelectSingleNode("/detailed").InnerXml()
        addImportedNodes(xmlImportDoc.SelectSingleNode("/detailed"))
        Dim existingInput As String = ""
        Try
            existingInput = frmMain.xmlDoc.SelectSingleNode("/metadata/eainfo/detailed").InnerXml()
        Catch ex As Exception
        End Try
        'editXMLFile()
        editNode.Remove("/metadata/eainfo", "detailed")
        editNode.Add("/metadata/eainfo", "detailed", "detailed", existingInput & importXML)
    End Sub
    Public Sub addImportedNodes(ByVal xml_node As XmlNode)
        Dim entityLabel As String = ""
        Dim entityDef As String = ""
        Dim entitySource As String = ""
        Dim entityClass As EAdetailClass = New EAdetailClass()
        Dim newNode As TreeNode = New TreeNode()

        For Each child As XmlNode In xml_node.ChildNodes()
            If child.Name = "enttyp" Then
                For Each subchild As XmlNode In child.ChildNodes()
                    If subchild.Name = "enttypl" Then
                        entityLabel = subchild.InnerText
                    ElseIf subchild.Name = "enttypd" Then
                        entityDef = subchild.InnerText
                    ElseIf subchild.Name = "enttypds" Then
                        entitySource = subchild.InnerText
                    End If
                Next
                entityClass.EntityLabel = entityLabel
                entityClass.EntityDef = entityDef
                entityClass.DefSource = entitySource
                entityClass.EntityType = "Entity"
                Dim node2add As String = "ROOT"
                Dim node As TreeNode = New TreeNode()
                node = treeview_elements.Nodes(0)
                newNode.Text = entityLabel
                newNode.Name = entityLabel
                node.Nodes.Add(newNode)
                cEAentities.Add(entityClass, newNode.FullPath()) 'add new detailed description to collection with key
                node.Expand()
                treeview_elements.Update()
            ElseIf child.Name = "attr" Then
                insertAttributes(child, newNode)
            End If
        Next
    End Sub
    Private Sub insertAttributes(ByVal child As XmlNode, ByVal entityNode As TreeNode)
        Dim attrLabel As String = ""
        Dim attrDef As String = ""
        Dim attrSource As String = ""
        Dim attrDates As StringCollection = New StringCollection()
        Dim attrAccuracy As String = ""
        Dim attrExplanation As String = ""
        Dim attrMeasurementFreq As String = ""
        Dim attrClass As AttribClass = New AttribClass()

        Dim attrNode As TreeNode = New TreeNode()

        For Each subchild As XmlNode In child.ChildNodes()
            If subchild.Name = "attrlabl" Then
                attrLabel = subchild.InnerText
            ElseIf subchild.Name = "attrdef" Then
                attrDef = subchild.InnerText
            ElseIf subchild.Name = "attrdefs" Then
                attrSource = subchild.InnerText
            ElseIf subchild.Name = "attrmfrq" Then
                attrMeasurementFreq = subchild.InnerText
            ElseIf subchild.Name = "attrvai" Then
                For Each subsubchild As XmlNode In subchild.ChildNodes()
                    If subsubchild.Name = "attrva" Then
                        attrAccuracy = subsubchild.InnerText
                    ElseIf subsubchild.Name = "attrvae" Then
                        attrExplanation = subsubchild.InnerText
                    End If
                Next
            ElseIf subchild.Name = "begdatea" Then
                Dim datevalue As String = ""
                datevalue = subchild.InnerText
                If subchild.NextSibling.Name = "enddatea" Then datevalue = datevalue & sPdelim & subchild.NextSibling.InnerText
                attrDates.Add(datevalue)
            ElseIf subchild.Name = "attrdomv" Then
                If attrNode.Name = "" Then
                    attrNode = addAttrNode(entityNode, attrClass, attrLabel, attrDef, attrSource, attrMeasurementFreq, attrAccuracy, attrExplanation, attrDates)
                End If
                insertDomainValues(subchild, attrNode)
            End If
        Next
    End Sub
    Private Function addAttrNode(ByVal entityNode As TreeNode, ByVal attrClass As AttribClass, ByVal attrLabel As String, ByVal attrDef As String, ByVal attrSource As String, ByVal attrMeasurementFreq As String, ByVal attrAccuracy As String, ByVal attrExplanation As String, ByVal attrDates As StringCollection) As TreeNode
        attrClass.Label = attrLabel
        attrClass.Definition = attrDef
        attrClass.DefSource = attrSource
        attrClass.MeasureFreq = attrMeasurementFreq
        If attrAccuracy <> "" Then attrClass.Accuracy = attrAccuracy
        attrClass.AccExplain = attrExplanation
        attrClass.ValueDates = attrDates
        Dim node As TreeNode = New TreeNode()
        node = entityNode
        Dim newNode As TreeNode = New TreeNode()
        newNode.Text = attrLabel
        newNode.Name = attrLabel
        node.Nodes.Add(newNode)
        cEAttribs.Add(attrClass, newNode.FullPath()) 'add new detailed description to collection with key
        node.Expand()
        treeview_elements.Update()
        Return newNode
    End Function
    Private Sub insertDomainValues(ByVal subchild As XmlNode, ByVal attrNode As TreeNode)
        Dim domainNode As TreeNode = New TreeNode()

        For Each subsubchild As XmlNode In subchild.ChildNodes()
            Dim node2 As TreeNode = New TreeNode()
            node2 = attrNode
            Dim newNode2 As TreeNode = New TreeNode()

            If subsubchild.Name = "rdom" Then
                Dim rangeValue As AttribDomain_Range = New AttribDomain_Range()
                For Each subsubsubchild As XmlNode In subsubchild.ChildNodes()
                    If subsubsubchild.Name = "rdommin" Then
                        rangeValue.DomMinimum = subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "rdommax" Then
                        rangeValue.DomMaximum = subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "attrunit" Then
                        rangeValue.MeasureUnits = subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "attrmres" Then
                        rangeValue.Resolution = subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "attr" Then
                        If domainNode.Name = "" Then
                            domainNode = addDomainRangeNode(rangeValue, attrNode)
                        End If
                        Dim s1 As String = "Range: min = " & rangeValue.DomMinimum & "  max = " & rangeValue.DomMaximum
                        insertAttributes(subsubsubchild, domainNode) 'controlthis
                    End If
                Next
                If domainNode.Name = "" Then
                    domainNode = addDomainRangeNode(rangeValue, attrNode)
                End If
            ElseIf subsubchild.Name = "edom" Then
                Dim enumValue As AttribDomain_Enum = New AttribDomain_Enum()
                Dim s1 As String = ""
                For Each subsubsubchild As XmlNode In subsubchild.ChildNodes()
                    If subsubsubchild.Name = "edomv" Then
                        enumValue.DomainValue = subsubsubchild.InnerText
                        s1 = "Enumerated: " & subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "edomvd" Then
                        enumValue.ValueDef = subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "edomvds" Then
                        enumValue.DefSource = subsubsubchild.InnerText
                    ElseIf subsubsubchild.Name = "attr" Then
                        If domainNode.Name = "" Then
                            domainNode = addDomainEnumNode(s1, enumValue, attrNode)
                        End If
                        insertAttributes(subsubsubchild, domainNode) 'controlthis
                    End If
                Next
                If domainNode.Name = "" Then
                    domainNode = addDomainEnumNode(s1, enumValue, attrNode)
                End If
            ElseIf subsubchild.Name = "codesetd" Then
                Dim codesetValue As String = ""
                For Each subsubsubchild As XmlNode In subsubchild.ChildNodes()
                    If subsubsubchild.Name = "codesetn" Then
                        codesetValue = subsubsubchild.InnerText & sPdelim
                    ElseIf subsubsubchild.Name = "codesets" Then
                        codesetValue = codesetValue & subsubsubchild.InnerText
                    End If
                Next
                Dim s1 As String = "Codeset: " & codesetValue.Split(sPdelim)(0)
                newNode2.Text = s1
                newNode2.Name = s1
                node2.Nodes.Add(newNode2)
                cEAdomains.Add(codesetValue, newNode2.FullPath)
                cEAdomtypes.Add("codeset", newNode2.FullPath)
                node2.Expand()
            ElseIf subsubchild.Name = "udom" Then
                Dim s1 As String = "Unrepresentable: " & subsubchild.InnerText
                newNode2.Text = s1
                newNode2.Name = s1
                node2.Nodes.Add(newNode2)
                cEAdomains.Add(subsubchild.InnerText, newNode2.FullPath)
                cEAdomtypes.Add("unrep", newNode2.FullPath)
                node2.Expand()
            End If
        Next
    End Sub
    Private Function addDomainEnumNode(ByVal s1 As String, ByVal enumValue As AttribDomain_Enum, ByVal attrNode As TreeNode) As TreeNode
        'Dim node2add2 As String = attrLabel
        Dim node2 As TreeNode = New TreeNode()
        node2 = attrNode
        'For Each treenodeitem As TreeNode In treeview_elements.Nodes
        'node2 = recursiveTreeView(treenodeitem, node2add2)
        'Next
        Dim newNode2 As TreeNode = New TreeNode()

        newNode2.Text = s1
        newNode2.Name = s1
        node2.Nodes.Add(newNode2)
        cEAdomains.Add(enumValue, newNode2.FullPath)
        cEAdomtypes.Add("enum", newNode2.FullPath)
        node2.Expand()
        Return newNode2
    End Function
    Private Function addDomainRangeNode(ByVal rangeValue As AttribDomain_Range, ByVal attrNode As TreeNode) As TreeNode
        'Dim node2add2 As String = attrLabel
        Dim node2 As TreeNode = New TreeNode()
        node2 = attrNode
        'For Each treenodeitem As TreeNode In treeview_elements.Nodes
        'node2 = recursiveTreeView(treenodeitem, node2add2)
        'Next
        Dim newNode2 As TreeNode = New TreeNode()

        Dim s1 As String = "Range: min = " & rangeValue.DomMinimum & "  max = " & rangeValue.DomMaximum
        newNode2.Text = s1
        newNode2.Name = s1
        node2.Nodes.Add(newNode2)
        cEAdomains.Add(rangeValue, newNode2.FullPath)
        cEAdomtypes.Add("range", newNode2.FullPath)
        node2.Expand()
        Return newNode2
    End Function

    Private Sub ALLToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ALLToolStripMenuItem.Click
        exportAllEntities()
    End Sub

    Private Sub SelectedItemsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectedItemsToolStripMenuItem.Click
        exportSelectedEntities()
    End Sub

    Private Sub IMPORTToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IMPORTToolStripMenuItem.Click
        button_import_Click(sender, e)
    End Sub
#End Region

End Class

